package org.sbbs.app.demo.webapp.action;

import org.sbbs.app.demo.model.DemoEntity;
import org.sbbs.app.demo.service.DemoEntityManager;
import org.sbbs.base.pager.IPager;
import org.sbbs.base.pager.impl.JqgridPagerImpl;
import org.sbbs.base.searcher.SearchFilter;
import org.sbbs.base.searcher.SearchFilterBuilder;
import org.sbbs.base.webapp.action.BaseJqgridPagedAction;

//@Actions({@Action(value = "/different/url", Results = { @Result(name = "success", location="demoEntity/demoEntityList.jsp") }) })
public class DemoEntityPagedAction
    extends BaseJqgridPagedAction {
    private DemoEntityManager demoEntityManager;

    public DemoEntityManager getDemoEntityManager() {
        return demoEntityManager;
    }

    public void setDemoEntityManager( DemoEntityManager demoEntityManager ) {
        this.demoEntityManager = demoEntityManager;
    }

    @Override
    public int getSearchFilterType() {
        return SearchFilterBuilder.PROPERTY_FILTER;
    }

    @Override
    public Class getSearchEntityClazz() {
        return DemoEntity.class;
    }

    public String gridPageSave() {
        return null;
    }

    /*
     * public String gridPageList() { try { IPager pager = new JqgridPagerImpl(getRequest()); SearchFilter sf =
     * SearchFilterBuilder.buildSearchFilter( getRequest(), SearchFilterBuilder.JQGRID_SELF); pager =
     * this.hibernateCriteriaPagedQueryDao.pagedQuery( DemoEntity.class, pager, sf); this.pageList = pager.getList();
     * records = pager.getTotalNumberOfRows(); total = pager.getTotalNumberOfPages(); page = pager.getPageNumber(); }
     * catch (Exception e) { log.error("GridList Error", e); } return SUCCESS; }
     */

    @Override
    public String gridPageList() {
        try {
            IPager pager = new JqgridPagerImpl( getRequest() );
            SearchFilter sf = SearchFilterBuilder.buildSearchFilter( getRequest(), this.getSearchFilterType() );
            pager = this.demoEntityManager.pagedQuery( this.getSearchEntityClazz(), pager, sf );

            this.pageList = pager.getList();
            records = pager.getTotalNumberOfRows();
            total = pager.getTotalNumberOfPages();
            page = pager.getPageNumber();

        }
        catch ( Exception e ) {
            log.error( "GridList Error", e );
        }
        return SUCCESS;
    }
}
